import os

# 遍历目录及子目录
for root, dirs, files in os.walk('.'):
    for file in files:
        # 检查文件扩展名
        if file.endswith(('.c', '.h', '.r')):
            new_file_name = file

            # 替换文件名中的 'av' 为 'dp' 和 'Av' 为 'Dp'
            new_file_name = new_file_name.replace('av', 'dp')
            new_file_name = new_file_name.replace('Av', 'Dp')

            # 如果文件名发生变化，进行重命名
            if new_file_name != file:
                old_file_path = os.path.join(root, file)
                new_file_path = os.path.join(root, new_file_name)

                # 执行重命名
                os.rename(old_file_path, new_file_path)
                print(f"Renamed: {old_file_path} -> {new_file_path}")
